package cn.iocoder.yudao.module.team.service.idcard;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.team.dal.dataobject.orde.OrdeDO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.team.controller.admin.idcard.vo.*;
import cn.iocoder.yudao.module.team.dal.dataobject.idcard.IdcardDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.team.dal.mysql.idcard.IdcardMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.team.enums.ErrorCodeConstants.*;

/**
 * 客人身份证信息 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class IdcardServiceImpl implements IdcardService {

    @Resource
    private IdcardMapper idcardMapper;

    @Override
    public Integer createIdcard(IdcardSaveReqVO createReqVO) {
        // 插入
        IdcardDO idcard = BeanUtils.toBean(createReqVO, IdcardDO.class);
        idcardMapper.insert(idcard);

        // 返回
        return idcard.getId();
    }

    @Override
    public void updateIdcard(IdcardSaveReqVO updateReqVO) {
        // 校验存在
        validateIdcardExists(updateReqVO.getId());
        // 更新
        IdcardDO updateObj = BeanUtils.toBean(updateReqVO, IdcardDO.class);
        idcardMapper.updateById(updateObj);
    }

    @Override
    public void deleteIdcard(Integer id) {
        // 校验存在
        validateIdcardExists(id);
        // 删除
        idcardMapper.deleteById(id);
    }

    @Override
        public void deleteIdcardListByIds(List<Integer> ids) {
        // 删除
        idcardMapper.deleteByIds(ids);
        }


    private void validateIdcardExists(Integer id) {
        if (idcardMapper.selectById(id) == null) {
            throw exception(IDCARD_NOT_EXISTS);
        }
    }

    @Override
    public IdcardDO getIdcard(Integer id) {
        return idcardMapper.selectById(id);
    }

    @Override
    public PageResult<IdcardDO> getIdcardPage(IdcardPageReqVO pageReqVO) {
        return idcardMapper.selectPage(pageReqVO);
    }

    @Override
    public void createBatch(List<IdcardDO> updateReqVO) {
        idcardMapper.insertOrUpdate(updateReqVO);
    }

}